package com.itheima.edu.info.manager.service;

import com.itheima.edu.info.manager.dao.BaseStudentDao;
import com.itheima.edu.info.manager.domain.Student;
import com.itheima.edu.info.manager.factory.StudentDaoFactory;

/*
业务层:
1.整理的所用方法(功能)给客服用
2.如果某些业务涉及到要对数据仓库进行访问的话,对业务员操管对象
 */
@SuppressWarnings(value = "all")
public class StudentService {
    private BaseStudentDao studentDao = StudentDaoFactory.getStudentDao();

    //添加学生
    public boolean addStudent(Student student) {

        return studentDao.addStudent(student);
    }
//给出指定学号,判断在数组中是否存在
    public boolean isExists(String sid) {
        Student[] stuArray = studentDao.findAllStudent();
        boolean flag = false;//标记位,先假设数据仓库中没有用户录入的学号
        for (int i = 0; i < stuArray.length; i++) {
            Student student = stuArray[i];
            if (student != null && student.getSid().equals(sid)) {//先确定数组不为空
                flag = true;
                break;
            }
        }
        return flag;
    }

    public Student[] findAllStudent() {
        Student[] allStudent = studentDao.findAllStudent();
        boolean flag = false;
        for (int i = 0; i < allStudent.length; i++) {
            Student stu = allStudent[i];
            if (stu != null) {
                flag = true;
                break;
            }
        }
        if (flag) {
            return allStudent;
        } else {
            return null;
        }
    }

    public void deleteStudent(String delId) {

        studentDao.deleteStudent(delId);
    }

    public void updateStudent(String updateId, Student newStu) {
             studentDao.updateStudent(updateId,newStu);
    }
}
